package com.imti.controller;




import com.imti.Api.CommonResult;
import com.imti.entity.PatientDot;
import com.imti.entity.Patient;
import com.imti.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (Patient)表控制层
 *
 * @author makejava
 * @since 2023-02-01 08:43:22
 */
@RestController
@RequestMapping("patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    /**
     * 根据患者账号查询
     * @param accId
     * @return
     */
    @RequestMapping("/findPatByAccId")
    @ResponseBody
    public CommonResult<Patient> findPatByAccId(int accId){
        return CommonResult.success(patientService.findPatByAccId(accId));
    }

    /**
     * 添加患者
     * @param patient
     * @return
     */
    @RequestMapping("/addPat")
    public CommonResult<Integer> addPat(Patient patient){
        String name= patient.getPatName();
        String cardCode= patient.getCardCode();
        String sex=  patient.getPatSex();
        if ("男".equals(sex)){
            patient.setPatSex("1");
        }else{
            patient.setPatSex("0");
        }
        String birthday=  patient.getPatBirthday();
        String phone=  patient.getPatPhone();
        String live=  patient.getPatLive();
        String address=  patient.getPatAddress();
        if (!"".equals(name)&&name!=null&&!"".equals(cardCode)&&cardCode!=null&&!"".equals(sex)&&sex!=null&&!"".equals(birthday)&&birthday!=null&&!"".equals(phone)&&phone!=null&&!"".equals(patient.getPatLive())&&live!=null&&!"".equals(address)&&address!=null){
        return CommonResult.success(patientService.addPat(patient));
        }else{
            return CommonResult.failed();
        }

    }

    /**
     * 根据患者身份证号查询患者信息和诊疗号
     * @param cardCode
     * @return
     */
    @PostMapping("/getPatCardCode")
    @ResponseBody
    public CommonResult<List<PatientDot>> getPatCardCode(String cardCode){
        if (cardCode==""||cardCode==null){
            cardCode="";
        }
        return CommonResult.success(patientService.getPatCardCode(cardCode));
    }

}


